﻿var markersArray = [];
var map;

function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 2,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}

function clearOverlays() {
    if (markersArray) {
        for (i in markersArray) {
            markersArray[i].setMap(null);
        }
    }
}

function FilterMap(fromYear, toYear, fromDepth, toDepth, fromMagni, toMagni) {
    var url = '/quakes/Home/FilterQuakes' +
                                        '?fromYear=' + fromYear +
                                        '&toYear=' + toYear +
                                        '&fromDepth=' + fromDepth +
                                        '&toDepth=' + toDepth +
                                        '&fromMagni=' + fromMagni +
                                        '&toMagni=' + toMagni;


    $.getJSON(url, function (data) {
        $.each(data, function (key, val) {
            var tempCoord = new google.maps.LatLng(val.Latitude, val.Longitude, true);

            var d = new Date(val.Date);

            var marker = new google.maps.Marker({
                position: tempCoord,
                map: map,
                optimized: false,
                title: "Date: " + d + "\n" +
                        "Depth: " + val.Depth + "\n" +
                        "Magnitude: " + val.Magnitude,
                icon: val.IconImage
            });
            markersArray.push(marker);
        });
    });
}